#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
# author:hengk
# contact: hengk@foxmail.com
# datetime:2019-10-23 12:40
"""
from base2txt import BaseTrans
import os
import xlrd
class Excel2Txt(BaseTrans):

    @staticmethod
    def tran2txt(src_filename,dst_filename):
        workbook = xlrd.open_workbook(src_filename)
        str = ""
        for sheet_name in workbook.sheet_names():
            sheet = workbook.sheet_by_name(sheet_name)
            for row_index in range(sheet.nrows):
                str +="".join(sheet.row_values(row_index))
        with open(dst_filename, 'w') as f:
            f.write(str)



if __name__ == '__main__':
    excels_path = "/home/kangheng/generators/text_generators/data/excels"
    corpus_path = "/home/kangheng/generators/text_generators/data/corpus"
    filenames = os.listdir(excels_path)
    trans = Excel2Txt()
    for filename in filenames:
        print(filename)
        src_name = os.path.join(excels_path,filename)
        dst_name = os.path.join(corpus_path,filename[0:filename.rfind(".")]+".txt")
        trans.tran2txt(src_name,dst_name)
